package com.zty.xiaomiadmin.server.Service.Evidence;


import com.zty.xiaomiadmin.server.Dao.EvidenceMapper;
import com.zty.xiaomiadmin.server.Dao.ServiceOrderMapper;
import com.zty.xiaomiadmin.server.Entity.Evidence.Evidence;
import com.zty.xiaomiadmin.server.utils.SqlSessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.io.IOException;
import java.util.List;
@Service
public class EvidenceServiceImp implements EvidenceService{

    @Override
    public List<Evidence> getEvidenceByTribunalId(int tribunal_id) throws IOException {
        return SqlSessionUtil.getSqlSessionInstance().getSqlSession()
                .getMapper(EvidenceMapper.class).getEvidenceByTribunalId(tribunal_id);
    }

    @Override
    public int addEvidenceByTribunalId(Evidence evidence) throws IOException {
        int num = SqlSessionUtil.getSqlSessionInstance().getSqlSession()
                .getMapper(EvidenceMapper.class).addEvidenceByTribunalId(evidence);
        if (num != 1) {
            SqlSessionUtil.getSqlSessionInstance().getSqlSession().rollback();
        } else {
            SqlSessionUtil.getSqlSessionInstance().getSqlSession().commit();
        }
        return num;
    }
}
